<script setup>
import HomePanel from './HomePanel.vue'
import { onMounted, ref } from 'vue'
import goodsImg1 from '@/assets/uploads/新鲜好物1.png'
import goodsImg2 from '@/assets/uploads/新鲜好物2.png'
import goodsImg3 from '@/assets/uploads/新鲜好物3.png'
import goodsImg4 from '@/assets/uploads/新鲜好物4.png'

// 使用静态数据和本地图片
const newList = ref([
  {
    id: 1,
    name: '新鲜有机蔬菜套装',
    price: 99.9,
    picture: goodsImg1
  },
  {
    id: 2,
    name: '精选进口水果礼盒',
    price: 199.9,
    picture: goodsImg2
  },
  {
    id: 3,
    name: '农家散养土鸡蛋 30枚',
    price: 69.9,
    picture: goodsImg3
  },
  {
    id: 4,
    name: '新鲜三文鱼切片装',
    price: 129.9,
    picture: goodsImg4
  }
])

// 保留初始化函数以维持兼容性
const getNewList = async () => {
  // 已经有静态数据，不需要再请求
  console.log('使用静态新品数据')
}

// 组件挂载时仍调用函数，保持原有的行为模式
onMounted(() => getNewList())

</script>

<template>
  <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
    <ul class="goods-list">
      <li v-for="item in newList" :key="item.id">
        <RouterLink :to="`/detail/${item.id}`">
          <img :src="item.picture" alt="" />
          <p class="name">{{ item.name }}</p>
          <p class="price">&yen;{{ item.price }}</p>
        </RouterLink>
      </li>
    </ul>
  </HomePanel>
  <!-- 下面是插槽主体内容模版
  <ul class="goods-list">
    <li v-for="item in newList" :key="item.id">
      <RouterLink to="/">
        <img :src="item.picture" alt="" />
        <p class="name">{{ item.name }}</p>
        <p class="price">&yen;{{ item.price }}</p>
      </RouterLink>
    </li>
  </ul>
  -->
</template>


<style scoped lang='scss'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;

  li {
    width: 306px;
    height: 406px;

    background: #f0f9f4;
    transition: all .5s;

    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }

    img {
      width: 306px;
      height: 306px;
    }

    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }

    .price {
      color: $priceColor;
    }
  }
}
</style>